package com.fs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.pojo.InSto;

import com.fs.service.InStoService;
import com.fs.vo.*;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import com.fs.pojo.InSto;
import com.fs.service.InStoService;
import com.fs.util.ResponseDataUtil;
import com.fs.vo.ResponseData;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author yyds
 * @fileName RtaController
 * @date 2024/10/18 19:00
 * @description
 **/
@RestController
@RequestMapping("/insto")
public class InStoController {
    @Resource
    private InStoService inStoService;

    /**
     * 分页查所有入库申请
     *
     * @param condition
     * @return
     */
    @PostMapping("/list")
    public ResponseData<PageInfo<InSto>> findAll(@RequestBody Condition<InSto> condition) {
        return new ResponseData<>(ResultEnums.OK, inStoService.selectAll(condition));
    }

    /**
     * 新增入库申请
     *
     * @param condition
     * @return
     */
    @PostMapping("/addInSto")
    public ResponseData insertCheck(@RequestBody Condition<InSto> condition) {
        if (inStoService.addInSto(condition.getSearch()) != 0) {
            return new ResponseData<>(ResultEnums.OK);
        } else return new ResponseData<>(ResultEnums.FAIL);
    }

    /**
     * 删除入库申请
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteInSto/{id}")
    public ResponseData deleteInSto(@PathVariable Integer id) {
        if (inStoService.deleteInSto(id)) {
            return new ResponseData<>(ResultEnums.OK);
        } else return new ResponseData<>(ResultEnums.FAIL);
    }

    @PutMapping
    public ResponseData<Integer> addOrderDetail(@RequestBody InSto inSto) {
        Integer count = inStoService.addInSto(inSto);
        return count == 1 ? ResponseDataUtil.buildOk(200, "操作成功", count) : ResponseDataUtil.buildFail(null);
    }

    @PostMapping("/approve")
    public ResponseData approve(@RequestBody InSto inSto) {
        if (inStoService.approve(inSto)) {
            return new ResponseData<>(ResultEnums.OK);
        } else return new ResponseData<>(ResultEnums.FAIL);
    }

}
